package cn.zucc.edu.bruce.iot;

import android.content.Context;
import android.util.Log;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 *
 */
public class SocketServer extends Thread {
    private static ServerSocket sst = null;
    public static boolean isContinue = true;//表示接入的Socket是否继续执行
    private int port;
    private Context context;

    public SocketServer(int port,Context context) {
        this.port = port;
        this.context=context;
    }

    @Override
    public void run() {
        startServer();
    }

    private void startServer() {
        try {
            Log.e("server", "startServer: " );
            sst = new ServerSocket(port);
            while (true) {
                Socket s = sst.accept();
                new dealSocket(s,context).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static ServerSocket getSst() {
        return sst;
    }
}
